package com.electron.power.octopus.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.electron.power.model.mod.ModBodyMap;
import com.electron.power.octopus.service.ModBodyMapService;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("api/mod/modBody")
@Slf4j
public class ModBodyController {
	
	@Autowired
	private ModBodyMapService modeBodyMapService;


	@GetMapping(value = "all", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Flux<ModBodyMap> findAll() {
		return modeBodyMapService.findAll();
	}

	@ApiOperation("新增字符串数据")
	@PostMapping(value = "add", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Mono<ModBodyMap> add(@RequestBody ModBodyMap mod) {
		log.info("webflux 接收到的数据为:{}", mod);
		return modeBodyMapService.add(mod);
	}
	
	
	@GetMapping("/paged")
    public Flux<ModBodyMap> getQuoteFlux(final @RequestParam(name = "page") int page,
                                    final @RequestParam(name = "size") int size) {
        return modeBodyMapService.retrieveAllPaged(page, size);
    }
}
